#pragma once

#include "Singleton.h"
#include "FunctionMap.h"

struct MSG_BASE;
class User;

class GameServerSession;

class PacketHandler : public Singleton<PacketHandler>
{
	typedef VOID (*fnHandler_CP)( User *pUser, MSG_BASE *pMsg, WORD wSize );
	typedef VOID (*fnHandler_GB)( GameServerSession *pGameServerSession, MSG_BASE *pMsg, WORD wSize );
	

public:
	PacketHandler();
	~PacketHandler();

	BOOL			RegisterPackets();

	BOOL			ParsePacket_CP( User *pUser, MSG_BASE *pMsg, WORD wSize );
	BOOL			ParsePacket_GB( GameServerSession *pGameServerSession, MSG_BASE *pMsg, WORD wSize );
	

private:
	BOOL			RegClientPacket( BYTE category, BYTE protocol, PacketHandler::fnHandler_CP fnHandler );
	BOOL			RegGameServerPacket( BYTE category, BYTE protocol, PacketHandler::fnHandler_GB fnHandler );


	struct FUNC_CP : public util::BASE_FUNC
	{
		fnHandler_CP	m_fnHandler;
	};
	struct FUNC_GB : public util::BASE_FUNC
	{
		fnHandler_GB	m_fnHandler;
	};
	
	util::FunctionMap		*m_pFuncMap_CP;
	util::FunctionMap		*m_pFuncMap_GB;
};

